﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
using System.IO;
namespace Infrastructure.Aspect.Services.Serialization
{
    public class BinaryService :ISerializationService
    {
        public byte[] Serialization(object target)
        {
            BinaryFormatter bin = new BinaryFormatter();
            using(MemoryStream ms = new MemoryStream())
            {
                bin.Serialize(ms, target);
                return ms.ToArray();
            }            
        }
        public T DesSerialization<T>(byte[] target)
        {
            BinaryFormatter bin = new BinaryFormatter();
            using (MemoryStream ms = new MemoryStream(target))
            {
                var result = (T)bin.Deserialize(ms);
                return result;
            }            
        }
    }
}
